<?php if(!defined('BASEPATH')) exit ('No direct script access allowed');

class News extends public_controller
{
	
	public function __construct() {
		parent:: __construct();
		//$this->template->set_layout('person_layout');
		if(!$this->session->userdata('loginStatus')) redirect('landing');
		//$this->load->model('person/person_model');
		include_once(APPPATH . 'libraries/simple_html_dom' . EXT);
	}

	public function index(){
		$var = 'https://news.google.com/news/feeds?pz=1&cf=all&ned=in&hl=en&csid=b5f63adf179cb0e6&output=rss';
		$news = simplexml_load_file($var);

		$feeds = array();

		$i = 0;

		foreach ($news->channel->item as $item) 
		{
		    preg_match('@src="([^"]+)"@', $item->description, $match);
		    $parts = explode('<font size="-1">', $item->description);
		   // $extact = new SimpleXMLElement($item->pubDate);

		    $feeds[$i]['title'] = (string) $item->title;
		    $feeds[$i]['link'] = (string) $item->link;
		    $feeds[$i]['image'] = @$match[0];
		    $feeds[$i]['site_title'] = strip_tags($parts[1]);
		    $feeds[$i]['story'] = strip_tags($parts[2]);
		    $feeds[$i]['pubDate'] = (string)$item->pubDate;

		    $i++;
		}

		$crumb = array(
				'Home'	=> base_url(),
				'News' => '',
				'Latest News' => ''
			);

		$this->template->title('News')
			->set('feeds', $feeds)
			->set('crumb',$crumb)
			->build('news/index');

	}
}